<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>全选按钮</title>
		<script>
			function quanxuan() {
				var quanxuan = document.getElementById("quanxuan");
				var choices = document.getElementsByName("choose");
				for(var i = 0; i < choices.length; i++) {
						choices[i].checked = quanxuan.checked;
				}
			
			}
			function quanxuan2() {
				
				var quanxuan = document.getElementById("quanxuan");
				var choices = document.getElementsByName("choose");
				for(var i = 0; i < choices.length; i++) {
					if(choices[i].checked ==true){
						quanxuan.checked=true;
						break;
					}else{
						quanxuan.checked=false;
					}
						 
				}
			
			}
		</script>
	</head>
	<body>
		全选<input type="checkbox" value="quanxuan" id="quanxuan" onclick="quanxuan()">
		1<input type="checkbox" value="choice1" name="choose" onclick="quanxuan2()">
		2<input type="checkbox" value="choice2" name="choose" onclick="quanxuan2()">
		3<input type="checkbox" value="choice3" name="choose" onclick="quanxuan2()">
	</body>
</html>
